#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <random>
#include <map>
#include <set>
using namespace std;
#define test(x) cout << "see: " << x << '\n';
const int N = 2e5 + 19;
int power[N], pw=1,n,m,T,A[N],a[N],c[N],pws[64],len;struct node{int val,id;}Q[N+N];
char s[N];
void solve() {
long long ans=0;
			for (int i=1;i<=m;++i) {
				long long tot=0,P=*lower_bound(pws+1,pws+1+len,c[i]);
				for (int k=1;k<=P;++k){
				int from=1; for (int p=1;p<=P;++p) Q[p]={(p<=c[i]?a[p]:-1),p};
				int to=P,cnt=0;int R=0,S=n;
				while (from!=to) { ++R;
					int Fr=to+1,To=to;
					for (int j=from;j<=to;j+=2) {
						++cnt;
						if (s[cnt]=='1')swap(Q[j],Q[j+1]);// if(from==5)cout<<cnt<<'\n';
						if (Q[j].val<R&&Q[j].val!=-1) Q[++To]=Q[j+1];
						else if (Q[j].val==-1) {
							if (Q[j+1].id!=k) Q[++To]=((Q[j+1].val<R&&Q[j].id!=k)?Q[j+1]:Q[j]);
							else Q[++To]=Q[j+1];
						}else Q[++To]=Q[j];
					}cnt-=(to-from+1)/2;S/=2;cnt+=S;//test(S);
					from=Fr,to=To;
				}
				if (Q[from].id==k)tot+=k;
				}ans^=tot*i;//test(tot);
			}
		printf("%lld\n",ans);
}
int main() {
	freopen("arena.in","r",stdin);
	freopen("arena.out","w",stdout);
	for (;pw<=1e5;pw*=2) power[pw]=1,pws[++len]=pw;
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;++i)scanf("%d",&A[i]);
	for (int i=1;i<=m;++i)scanf("%d",&c[i]);
	while (!power[n])++n;
	int to=0,p=n;
	while (to!=n-1) {
		p/=2;scanf("%s",s+1+to);to+=p;
	}
	int F=0;
	for (int i=1;i<=m;++i)F&=power[c[i]];
	scanf("%d",&T);
	while(T--) {
		int X[4];
		for (int i=0;i<4;++i) scanf("%d",&X[i]);
		for (int i=1;i<=n;++i) a[i]=A[i]^X[i%4];
		if (F) solve();
		else {
			long long ans=0;
			for (int i=1;i<=m;++i) {
				long long tot=0,P=*lower_bound(pws+1,pws+1+len,c[i]);
				for (int k=1;k<=P;++k){
				int from=1; for (int p=1;p<=P;++p) Q[p]={(p<=c[i]?a[p]:-1),p};
				int to=P,cnt=0;int R=0,S=n;
				while (from!=to) { ++R;
					int Fr=to+1,To=to;
					for (int j=from;j<=to;j+=2) {
						++cnt;
						if (s[cnt]=='1')swap(Q[j],Q[j+1]);// if(from==5)cout<<cnt<<'\n';
						if (Q[j].val<R&&Q[j].val!=-1) Q[++To]=Q[j+1];
						else if (Q[j].val==-1) {
							if (Q[j+1].id!=k) Q[++To]=((Q[j+1].val<R&&Q[j].id!=k)?Q[j+1]:Q[j]);
							else Q[++To]=Q[j+1];
						}else Q[++To]=Q[j];
					}cnt-=(to-from+1)/2;S/=2;cnt+=S;//test(S);
					from=Fr,to=To;
				}
				if (Q[from].id==k)tot+=k;
				}ans^=tot*i;//test(tot);
			}
		printf("%lld\n",ans);}
	}
	return 0;
}
/*
5 5
0 0 0 0 0
5 4 1 2 3
1001
10
1
1
2 1 0 0
*/